﻿using System;
using System.Linq;
using System.Web.Mvc;
using BLL;
using Model;

namespace Web.Areas.Manager.Controllers
{
    [NoCache]
    [HandleError]
    [UserAuthorize]
    public class Template_TypeController : Controller
    {
        Template_Type_BLL _Template_Type_BLL = new Template_Type_BLL();

        public virtual ActionResult Index(int? pageIndex, string keyword)
        {
            var model = _Template_Type_BLL.Get();
            if (!string.IsNullOrEmpty(keyword))
            {
                model = model.Where(a => a.Type.Contains(keyword));
            }
            return View(model.ToPagedList(pageIndex));
        }

        public virtual ActionResult Details(Guid id)
        {
            var item = _Template_Type_BLL.Get(id);
            return View(item);
        }

        public virtual ActionResult Edit(Guid? id)
        {
            var item = _Template_Type_BLL.Get(id);
            return View(item);
        }

        [HttpPost]
        public virtual ActionResult Edit(Guid? id, Template_Type collection)
        {
            Edit(id);

            if (!ModelState.IsValid)
            {
                return View();
            }

            _Template_Type_BLL.Save(id, ref collection);
            return RedirectToAction("Index", RouteData.Values);
        }

        [HttpDelete]
        public virtual ActionResult Delete(Guid Id)
        {
            _Template_Type_BLL.DeleteObject(Id);
            return RedirectToAction("Index", RouteData.Values);
        }
    }
}
